package com.ruoyi.wms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.wms.domain.WmsMeasuringUnitConversion;
import com.ruoyi.wms.service.IWmsMeasuringUnitConversionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 换算Controller
 * 
 * @author ruoyi
 * @date 2022-02-28
 */
@RestController
@RequestMapping("/wms/unitConversion")
public class WmsMeasuringUnitConversionController extends BaseController
{
    @Autowired
    private IWmsMeasuringUnitConversionService wmsMeasuringUnitConversionService;

    /**
     * 查询换算列表
     */
    @PreAuthorize(hasPermi = "wms:unitConversion:list")
    @GetMapping("/list")
    public TableDataInfo list(WmsMeasuringUnitConversion wmsMeasuringUnitConversion)
    {
        startPage();
        List<WmsMeasuringUnitConversion> list = wmsMeasuringUnitConversionService.selectWmsMeasuringUnitConversionList(wmsMeasuringUnitConversion);
        return getDataTable(list);
    }

    /**
     * 导出换算列表
     */
    @PreAuthorize(hasPermi = "wms:unitConversion:export")
    @Log(title = "换算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsMeasuringUnitConversion wmsMeasuringUnitConversion) throws IOException
    {
        List<WmsMeasuringUnitConversion> list = wmsMeasuringUnitConversionService.selectWmsMeasuringUnitConversionList(wmsMeasuringUnitConversion);
        ExcelUtil<WmsMeasuringUnitConversion> util = new ExcelUtil<WmsMeasuringUnitConversion>(WmsMeasuringUnitConversion.class);
        util.exportExcel(response, list, "换算数据");
    }

    /**
     * 获取换算详细信息
     */
    @PreAuthorize(hasPermi = "wms:unitConversion:query")
    @GetMapping(value = "/{mucUuid}")
    public AjaxResult getInfo(@PathVariable("mucUuid") String mucUuid)
    {
        return AjaxResult.success(wmsMeasuringUnitConversionService.selectWmsMeasuringUnitConversionByMucUuid(mucUuid));
    }

    /**
     * 新增换算
     */
    @PreAuthorize(hasPermi = "wms:unitConversion:add")
    @Log(title = "换算", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsMeasuringUnitConversion wmsMeasuringUnitConversion)
    {
        wmsMeasuringUnitConversion.setCreateBy(SecurityUtils.getUsername());
        return toAjax(wmsMeasuringUnitConversionService.insertWmsMeasuringUnitConversion(wmsMeasuringUnitConversion));
    }

    /**
     * 修改换算
     */
    @PreAuthorize(hasPermi = "wms:unitConversion:edit")
    @Log(title = "换算", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsMeasuringUnitConversion wmsMeasuringUnitConversion)
    {
        return toAjax(wmsMeasuringUnitConversionService.updateWmsMeasuringUnitConversion(wmsMeasuringUnitConversion));
    }

    /**
     * 删除换算
     */
    @PreAuthorize(hasPermi = "wms:unitConversion:remove")
    @Log(title = "换算", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mucUuids}")
    public AjaxResult remove(@PathVariable String[] mucUuids)
    {
        return toAjax(wmsMeasuringUnitConversionService.deleteWmsMeasuringUnitConversionByMucUuids(mucUuids));
    }
}
